import {useState} from "react"

export const Strong = /^.*(?=.{8,16})(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&*?\(\)+=\[\]\{\}_<>,.;:'"-]).*$/;
export const Middle = /^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$/;
export const Weak = /^(?:\d+|[a-zA-Z]+|[!@#$%^&*]+)$/;

const usePwdDetection = () => {
  const [strength, $strength] = useState(0)
  const detection = (value) => {
    if (!value && value.length <= 6) $strength(0);
    if (Strong.test(value)) $strength(100);
    if (Middle.test(value)) $strength(75);
    if (Weak.test(value)) $strength(50);
  }

  return {
    strength,
    detection
  }
}

export default usePwdDetection